package com.egao.common.module.student.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.egao.common.module.student.entity.StudentSign;
import com.egao.common.module.student.entity.StudentSignAlter;
import com.egao.common.module.student.mapper.StudentSignAlterMapper;
import com.egao.common.module.student.service.StudentSignAlterService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author lym
 * @date 2023/7/6 9:57
 */
@Service
public class StudentSignAlterServiceImpl extends ServiceImpl<StudentSignAlterMapper, StudentSignAlter> implements StudentSignAlterService {

    @Override
    public void alterLog(StudentSign old, StudentSign studentSign, Integer loginUserId, String alterBy) {
        StudentSignAlter studentSignAlter = new StudentSignAlter();
        studentSignAlter.setStudentSignId(studentSign.getId());

        if (!StrUtil.isBlank(studentSign.getDispatchArchivesCompany()) && !studentSign.getDispatchArchivesCompany().equals(old.getDispatchArchivesCompany())) {
            studentSignAlter.setDispatchArchivesCompany(studentSign.getDispatchArchivesCompany());
            studentSignAlter.setOriginalDispatchArchivesCompany(old.getDispatchArchivesCompany());
        }

        if (!StrUtil.isBlank(studentSign.getDispatchArchivesAddress()) && !studentSign.getDispatchArchivesAddress().equals(old.getDispatchArchivesAddress())) {
            studentSignAlter.setDispatchArchivesAddress(studentSign.getDispatchArchivesAddress());
            studentSignAlter.setOriginalDispatchArchivesAddress(old.getDispatchArchivesAddress());
        }

        if (!StrUtil.isBlank(studentSign.getDispatchHkAddress()) && !studentSign.getDispatchHkAddress().equals(old.getDispatchHkAddress())) {
            studentSignAlter.setDispatchHkAddress(studentSign.getDispatchHkAddress());
            studentSignAlter.setOriginalDispatchHkAddress(old.getDispatchHkAddress());
        }

        studentSignAlter.setCreateBy(loginUserId);
        studentSignAlter.setAlterBy(alterBy);
        studentSignAlter.setCreateTime(new Date());
        baseMapper.insert(studentSignAlter);
    }

    @Override
    public List<StudentSignAlter> listByStudentSignId(Integer studentSignId) {
        return baseMapper.listByStudentSignId(studentSignId);
    }
}
